package com.hcbd.tdwt.util;

import android.content.Context;
import android.content.SharedPreferences;


/**
 * ���ش洢�๤��
 * @author mabo
 *
 */
public class SharedPreferencesUtil {


	private SharedPreferences sp;
	private SharedPreferences.Editor editor;

	public SharedPreferencesUtil(Context context){
		sp = context.getSharedPreferences("new_config", Context.MODE_MULTI_PROCESS);
		editor = sp.edit();
	}


	/**
	 * ����һ������ֵ
	 * @param attributeName
	 * @param attributeValue
	 * @throws Exception
	 */
	public void addAttribute(String attributeName, String attributeValue)  {
		try{
			editor.putString(attributeName, attributeValue);
			editor.commit();
		}catch (Exception ex){
			ex.printStackTrace();
		}
	}

	public void addImageRun(String attributeValue) {
		try{
			editor.putString("isImageRun", attributeValue);
			editor.commit();
		}catch (Exception ex){
		}
	}


	/**
	 * ����һ������ֵ
	 * @param attributeName
	 * @param attributeValue
	 * @throws Exception
	 */
	public void addAttribute(String attributeName, boolean attributeValue) throws Exception {
		try{
			editor.putBoolean(attributeName, attributeValue);
			editor.commit();
		}catch (Exception ex){
			throw new Exception();

		}
	}

	/**��ȡ����ֵ
	 *
	 * @param attributeName
	 * @return
	 */
	public String getAttribute(String attributeName){
		try{
			return sp.getString(attributeName, "");
		}catch(Exception ex){
			return "";
		}
	}

	/**
	 * ��ȡ����ֵ
	 * @param attributeName
	 * @param defaultattributeValue ��ȡ����Ĭ��Ϊ��ֵ
	 * @return
	 */
	public String getAttribute(String attributeName, String defaultattributeValue){
		try{
			return sp.getString(attributeName, defaultattributeValue);
		}catch(Exception ex){
			return defaultattributeValue;
		}
	}
	/**��ȡ����ֵ
	 *
	 * @param attributeName
	 * @return
	 */
	public boolean getAttributeBoolean(String attributeName){
		try{
			return sp.getBoolean(attributeName, false);
		}catch(Exception ex){
			return false;
		}
	}
	/**
	 * 存入对应的键值对
	 *
	 * @param key     键值
	 * @param value   对应的int值
	 */
	public  void addAttribute(String key, int value) {
		try{
			editor.putInt(key, value);
			editor.commit();
		}catch(Exception ex){
			ex.printStackTrace();
		}

	}
	public  int getAttributeInt(String key) {
		try{
			return	sp.getInt(key,-1);

		}catch(Exception ex){
			ex.printStackTrace();
		}
		return -1;
	}
}
